package servlet;

import dao.materialDAO;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 王开心
 * @Date: 2024/04/21/18:58
 * @Description:
 */
@WebServlet("/group/material/material_delete")
public class MaterialDeleteServlet extends HttpServlet {
    public MaterialDeleteServlet() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");

        // 获取要删除的记录的唯一标识，例如从请求参数中获取
        String  recordId = req.getParameter("r_id");
        int ret=materialDAO.deleteMaterialById(Integer.parseInt(recordId));
        resp.setHeader("refresh", "0;URL=" + "material_list");
    }
}
